﻿Public Class fZonas
    Dim daZonas As lbGlobalcom.dsGlobalTableAdapters.GLO_ZONASTableAdapter
    Dim daClave As lbGlobalcom.dsGlobalTableAdapters.GLO_CLAVESPRIMARIASTableAdapter

    Private Sub fZonas_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        Try
            If Me.DsGlobal.GLO_ZONAS.GetChanges IsNot Nothing Then
                GLO_ZONASBindingSource.EndEdit()
                If MessageBox.Show("Hay cambios pendientes por salvar, desea salvarlos", "Cambios pendientes", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
                    GLO_ZONASBindingNavigatorSaveItem.PerformClick()
                End If
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Henry")
        End Try
    End Sub

    Private Sub fZonas_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            daZonas = New lbGlobalcom.dsGlobalTableAdapters.GLO_ZONASTableAdapter
            daClave = New lbGlobalcom.dsGlobalTableAdapters.GLO_CLAVESPRIMARIASTableAdapter
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Henry")
        End Try
    End Sub

    Private Sub btnCargaZonas_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCargaZonas.Click
        Try
            If Me.DsGlobal.GLO_ZONAS.GetChanges IsNot Nothing Then
                GLO_ZONASBindingSource.EndEdit()
                If MessageBox.Show("Hay cambios pendientes por salvar, desea salvarlos", "Cambios pendientes", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
                    GLO_ZONASBindingNavigatorSaveItem.PerformClick()
                End If
            End If
            daZonas.Fill(DsGlobal.GLO_ZONAS)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Henry")
        End Try
    End Sub

    Private Sub GLO_ZONASBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GLO_ZONASBindingNavigatorSaveItem.Click
        Try
            Validate()
            GLO_ZONASBindingSource.EndEdit()
            daZonas.Update(DsGlobal.GLO_ZONAS)
            MessageBox.Show("Se salvarón registros con exito", "Salvar Registros", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Henry")
        End Try
    End Sub

    Private Sub BindingNavigatorDeleteItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BindingNavigatorDeleteItem.Click
        Try
            If MessageBox.Show("Esta se que desea eliminar este registro", "Elimina Registro", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
                GLO_ZONASBindingSource.Remove(GLO_ZONASBindingSource.Current)
                daZonas.Update(DsGlobal.GLO_ZONAS)
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Henry")
        End Try
    End Sub

    Private Sub GLO_ZONASDataGridView_CellBeginEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellCancelEventArgs) Handles GLO_ZONASDataGridView.CellBeginEdit
        Try
            If e.ColumnIndex = 1 AndAlso GLO_ZONASDataGridView.Rows(e.RowIndex).Cells(0).Value Is DBNull.Value Then
                Dim dt As lbGlobalcom.dsGlobal.GLO_CLAVESPRIMARIASDataTable
                dt = daClave.GetDataByIdClavePrimaria("GLO_ZONAS")
                If dt.Count Then
                    Dim dr As lbGlobalcom.dsGlobal.GLO_CLAVESPRIMARIASRow
                    dr = dt.Rows(0)
                    Dim Cons As lbGlobalcom.ConsecTablas = New lbGlobalcom.ConsecTablas(dr("TABLA"), dr("CAMPO"), dr("LONGITUD"))
                    GLO_ZONASDataGridView.Rows(e.RowIndex).Cells(0).Value = Cons.NumeroConsec
                    Cons = Nothing
                    GLO_ZONASBindingSource.EndEdit()
                    daZonas.Update(DsGlobal.GLO_ZONAS)
                End If
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub GLO_ZONASDataGridView_UserDeletedRow(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowEventArgs) Handles GLO_ZONASDataGridView.UserDeletedRow
        Try
            daZonas.Update(DsGlobal.GLO_ZONAS)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Henry")
        End Try
    End Sub

    Private Sub GLO_ZONASDataGridView_UserDeletingRow(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowCancelEventArgs) Handles GLO_ZONASDataGridView.UserDeletingRow
        If MessageBox.Show("Esta seguro que desea elimnar este registro", "Elimina registro", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.No Then
            e.Cancel = True
        End If
    End Sub

    Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Try
            'Dim ExpExc As ExportToExcel.ExportaToExcel = New ExportToExcel.ExportaToExcel(DsGlobal.GLO_ZONAS)
            'ExpExc.Export()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub
End Class